home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1993 May / Info-Mac_II_May_1993.to_.sit / Info-Mac II (May 1993).toast / Unix / Get Sumex Files.txt < prev    next >
Internet Message Format  |  1992-08-29  |  5KB

  1. Date:     Tue, 19 Mar 91 12:26:40 EST
  2. From: Tom Coradeschi <tcora@pica.army.mil>
  3. Subject:  Sumex & FTP
  4.  
  5.    Some folks on comp.sys.mac.comm have been enquiring about how to do ftp
  6. sessions with sumex, now that the 25 user limit has been imposed. The obvious
  7. solution is to run your ftp session at 5AM Pacific, but for left-coasters,
  8. and many of us to the east, that's a little difficult.
  9.  
  10.    One solution is to run your ftp session via a script. The following is
  11. one I've been using for a long time, and it seems to work quite well.
  12.  
  13.    In order to make the script capable of autonomously logging in (without
  14. your being there to give username and password), you need a '.netrc' file
  15. in your home directory. This file should have read and write permissions for
  16. the user only (chmod 600 .netrc), and be of the following format:
  17.  
  18. machine sumex-aim.stanford.edu,    login anonymous, password user@host.site.dom
  19.  
  20.    Fill in your own email address for the password.
  21.  
  22.    In order to run the shellscript during off hours, you can use one of these
  23. two methods (and I'm sure there are others).
  24.  
  25.    The first is to have the shellscript "sleep" for a given number of hours
  26. (seconds, actually). Let's say that it's 5PM, and you want the script to run
  27. at 2AM. 5PM->2AM= 9 hrs = 32,400 seconds. So, you type:
  28.  
  29. (sleep 32400;sumex.get)&
  30.  
  31.    Where the sleep 32400 command waits for 9 hrs, and sumex.get is the name
  32. of your shellscript. The & character is the Cshell command to run the
  33. process in the background. If you run bourne shell or k shell or whatever,
  34. you'll have to dig around for the appropriate command to do that. The ;
  35. separator tells your shell environment to run the commands sequentially, so
  36. after 32,400 seconds, sumex.get executes, and (hopefully) gets you your
  37. files.
  38.  
  39.    The second method is to use the "at" command. Here, the syntax is a
  40. little simpler, but you must be sure that at runs on your system. Again,
  41. there may be an equivalent command on your particular system. Simply type:
  42.  
  43. at 0200 sumex.get
  44.  
  45.    At 0200 hrs (2AM) sumex.get will execute.
  46.  
  47.    OK. On to the scripts. There are two files I'm including here, where one
  48. is the script and the other is the input file it looks for. In this case,
  49. I'm calling them sumex.get and sumex.files. Determining which is the script
  50. and which is the input file is left as an exercise for the reader:-}
  51.  
  52.    The shellscript does the following: It ftps to sumex, and tries to get
  53. the files called for in sumex.files. If it cannot successfully complete the
  54. ftp session, ie, some sort of an error is reported, that error is written to
  55. the errors file. The script checks on the size of the errors file, and if
  56. that file has size > 0, then it waits the interval you've designated, and
  57. tries the ftp session again.
  58.  
  59. ====file sumex.get====
  60. #!/bin/sh
  61. # Shell script to try repeatedly to get files via ftp from the host named
  62. # below. The host is repeatedly polled until the session is successfully
  63. # completed.
  64. # This is the site we're ftp'ing to.
  65. host=sumex-aim.stanford.edu
  66. # Define the input, result and error files.
  67. in=sumex.files
  68. out=$host.results
  69. err=$host.errs
  70. # How long to sleep between subsequent tries (in seconds):
  71. #time=600    # Ten minutes
  72. time=3600    # An hour
  73. #time=7200    # Two hours
  74. echo "Starting to get files from $host." > $out
  75. # Try to make connection w/out error loop first time
  76. # Initialize the error message file so we start the loop:
  77. echo "Trying to reach $host at time:" >> $out
  78. date +'%H:%M hrs; %d %h %y' >> $out
  79. ftp $host < $in >> $out 2> $err
  80. # MAIN LOOP: If error file isn't empty, we sleep for an hour and try again.
  81. while test -s $err
  82. do
  83.   echo "Cannot connect now, will try again in $time seconds." >> $out
  84.   sleep $time
  85.   echo "Trying to reach $host at time:" >> $out
  86.   date +'%H:%M hrs; %d %h %y' >> $out
  87.   ftp $host < $in >> $out 2> $err
  88. done
  89. echo "File transfer successful!" >> $out
  90. ====end sumex.get====
  91.  
  92.    The input file merely contains the commands you would type in, if you
  93. were doing this manually. Make sure!! that you include the quit command on
  94. the last line.
  95.  
  96. ====file sumex.files===
  97. cd info-mac/card
  98. get el-verbo-simple.hqx
  99. cd ../init
  100. get randomizer.hqx
  101. quit
  102. ====end sumex.files====
  103.  
  104.    I hope that my explanation has been clear enough. Really all you should
  105. have to do is to edit out all my bs and save the two files off separately.
  106. Make sure that the shellscript is executable ('chmod 744 sumex.get' should do
  107. it), and off you go...
  108.  
  109. tom coradeschi    <+>    tcora@pica.army.mil    <+>    tcora@dacth01.bitnet
  110.  
  111. PS: If your system doesn't run some sort of unix (UNIX, A/UX, SunOS, etc),
  112. all bets are off.
  113.  
  114.